package com.baymax.study.atomic.tools;

import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.Data;

/**
 * ResultMsg
 *
 * @author Baymax
 * @since 2024-07-22
 */
@Data
@JsonInclude(JsonInclude.Include.NON_NULL)
public class ResultMsg<T> {
    public static final int SUCCESS = 1;

    public static final int FAILED = 0;

    private int status;

    private String code;

    private String msg;

    private T data;

    public static <T> ResultMsg<T> buildSuccess(T param) {
        ResultMsg<T> resultMsg = new ResultMsg<>();
        resultMsg.setMsg("success");
        resultMsg.setStatus(SUCCESS);
        resultMsg.setData(param);
        return resultMsg;
    }

    public static <T> ResultMsg<T> buildSuccess() {
        ResultMsg<T> resultMsg = new ResultMsg<>();
        resultMsg.setMsg("success");
        resultMsg.setStatus(SUCCESS);
        return resultMsg;
    }

    public static ResultMsg<String> buildFailed(String errorMsg) {
        ResultMsg<String> resultMsg = new ResultMsg<>();
        resultMsg.setMsg(errorMsg);
        resultMsg.setStatus(FAILED);
        return resultMsg;
    }

    public static ResultMsg<String> buildFailed(String errorCode, String errorMsg) {
        ResultMsg<String> resultMsg = new ResultMsg<>();
        resultMsg.setStatus(FAILED);
        resultMsg.setCode(errorCode);
        resultMsg.setMsg(errorMsg);
        return resultMsg;
    }
}
